import request from '@/utils/request';

/**
 * 分页查询工厂地址
 */
export async function pageCustomerFactorys(params) {
  const res = await request.get('/order/customerFactory/page', { params });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询工厂地址列表
 */
export async function listCustomerFactorys(params) {
  const res = await request.get('/order/customerFactory', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询工厂地址
 */
export async function getCustomerFactory(id) {
  const res = await request.get('/order/customerFactory/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加工厂地址
 */
export async function addCustomerFactory(data) {
  const res = await request.post('/order/customerFactory', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改工厂地址
 */
export async function updateCustomerFactory(data) {
  const res = await request.put('/order/customerFactory', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除工厂地址
 */
export async function removeCustomerFactory(id) {
  const res = await request.delete('/order/customerFactory/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
